<template>
    <div>
        <h1>科室详情</h1>
        <table class="table table-bordered" style="background-color:lightpink;">
            <tbody>
                 <tr>
                    <td>科室名称</td>
                   <td> {{info.name}}</td>
                 </tr>
                  <tr>
                    <td>选择科室</td>
                    <td>
                        {{info.oname}}
                    </td>
                 </tr>
                  <tr>
                    <td>科室人数</td>
                    <td>{{info.people}}</td>
                 </tr>
                  <tr>
                    <td>科室描述</td>
                    <td>{{info.introduce}}</td>
                 </tr>
                  <tr>
                    <td>创建日期</td>
                    <td>{{info.createTime.substr(0,10)}}</td>
                 </tr>

                <tr>
                    <td></td>
                    <td><input type="button" value="返回" @click="fanhui" style="background-color: beige;"></td>
                </tr>
                
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import {ref,onMounted} from 'vue'
import { useRoute,useRouter } from 'vue-router';
let route=useRoute();
let router=useRouter();

onMounted(()=>{
    Getlevel();
    fan();
})
const fanhui=(id:any)=>{
    router.push({
        path:'/showOffcie',
        query:{
            id:id
        }
    })
}
let level:any=ref([]);

let info:any=ref({
  "id": 0,
  "people": "",
  "name": "",
  "introduce": "",
  "isdel": false,
  "createTime": "",
  "oid": ""
})
const fan=()=>{
    axios({
        url:'https://localhost:7292/api/Office/Fan',
        method:'get',
        params:{
            id:route.query.id,
        }
    })
    .then((res)=>{
        console.log(res.data);
        const data=res.data[0]
        Object.assign(info.value,res.data)
        // info.value = res.data
    })
    .catch((err)=>{
        console.log(err)
    })
}
  const add=()=>{
    if(info.value.name==""){
        alert("科室名称不能为空");
        return;
     }
     if(info.value.people==""){
        alert("科室人数不能为空");
        return;
     }
     if(info.value.introduce==""){
        alert("科室描述不能为空");
        return;
     }
     axios({
        url:'https://localhost:7292/api/Office/AddOffice',
        method:'post',
        data:info.value
     })
     .then((res)=>{
        console.log(res);
        if(res.data==-1){
            alert("科室名称重复了")
            return;
        }
        alert("添加成功");
        location.href='/showOffcie'
     })
     .catch((err)=>{
        console.log(err);
     })
  }

  const Getlevel=()=>{
     axios({
        url:'https://localhost:7292/api/Office/GetLevelOffcie',
        method:'get',
     })
     .then((res)=>{
        console.log(res);
        level.value=res.data
     })
     .catch((err)=>{
        console.log(err);
     })
  }
</script>

<style scoped>

</style>